app.controller("z-generatingWageData-c",['$scope','$rootScope','$z-http','$sce','z-generatingWageData-s','z-dictionary-s','z-corporation-s','z-department-s','z-edit-menu-s','z-salaryRequest-s','$filter',
    function($scope,$rootScope,$zhttp,$sce,Service,DictionaryService,CorporationService,DepartmentService,MenuService,RequestService,$filter){
	$scope.viewModel = {};
	
	//查询页面名称
	MenuService.getMenuByUrl({url:'generatingWageData'},
	function(data){	
		$scope.viewModel.menuList=data;
	},function(error) {});

	var now = new Date();                    //当前日期     
	var nowMonth = now.getMonth();           //当前月     
	var nowYear=$filter('date')(now,'yyyy'); //当前年
	//获取当月开始日期
	var monthStartDate = $filter("date")(new Date(nowYear, nowMonth, 1), "yyyy/MM/dd");
	//获取当前日期
    var dayEndDate= $filter("date")(now, "yyyy/MM/dd");
	$scope.viewModel.startDate=new Date(monthStartDate);    //起止日期
	$scope.viewModel.endDate=new Date(dayEndDate);	  	  //终止日期

	//日期控件
	$scope.viewModel.dateOptions = {
		formatYear: 'yy',
		startingDay: 1,
		showWeeks:false
	};
	//日期控件
	$scope.viewModel.format = "yyyy/MM/dd";
	//日期启动开关
	$scope.viewModel.startDateOpened = false;
	$scope.viewModel.endDateOpened = false;
	//起止日期选择
	$scope.viewModel.startDateOpen = function($event) {
		$event.preventDefault();
		$event.stopPropagation();
        $scope.viewModel.endDateOpened = false;
		$scope.viewModel.startDateOpened = !$scope.viewModel.startDateOpened;
	};
	//起止日期选择
	$scope.viewModel.endDateOpen = function($event) {
		$event.preventDefault();
		$event.stopPropagation();
        $scope.viewModel.startDateOpened = false;
		$scope.viewModel.endDateOpened = !$scope.viewModel.endDateOpened;
	};
	//生成
	$scope.viewModel.saveAttendanceReport=function(){
		$scope.viewModel.isLoading = true;
		Service.saveAttendanceReport(
                {beginDate:$scope.viewModel.startDate,
                 endDate:$scope.viewModel.endDate},
                function(data){
                	$rootScope.alertInfo("生成完成。");
                    $scope.viewModel.isLoading = false;
                },function(error) {
                    $scope.viewModel.isLoading = false;
                });
	};
	
}]);